package com.lyf.boot.config;

import com.lyf.boot.interceptor.AliPayInterceptor;
import com.lyf.boot.interceptor.WxPayInterceptor;
import com.lyf.boot.properties.AliPayProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Luyufan
 * @date 2023/8/22 11:21
 */
@Slf4j
@Configuration
@RequiredArgsConstructor
public class PayConfig implements WebMvcConfigurer {

    private final AliPayProperties aliPayProperties;

    @Override
    public void addInterceptors(@NonNull InterceptorRegistry registry) {
        if(aliPayProperties.isEnabled()){
            registry.addInterceptor(new AliPayInterceptor()).addPathPatterns(aliPayProperties.getApiPrefix() + "/**");
            log.info("添加支付宝支付拦截器");
        }
        registry.addInterceptor(new WxPayInterceptor()).addPathPatterns("/wxPay/**");

    }
}
